﻿using System;
using System.Configuration;
using System.Globalization;
using System.Web;

using BizElements.BusinessLayer;
using BizElements.Web;

namespace BizElements.Web
{
    /// <summary>Common static methods for Elements Framework configuration.</summary>
    public static class CommonGetters
    {
        #region GetUiCulture.

        /// <summary>Gets UI culture as defined in <see cref="UserSession"/>.</summary>
        /// <returns>Object stored in <see cref="UserSession.UiCulture"/>.</returns>
        public static CultureInfo GetUiCulture()
        {
            return UserSession.UiCulture;
        }

        #endregion

        #region GetActor.

        /// <summary>Gets current actor/user.</summary>
        /// <returns>Object stored in <see cref="UserSession.Actor"/>.</returns>
        public static IActor GetActor()
        {
            return UserSession.Actor;
        }

        #endregion

        #region GetSearchViewCacheKey.

        /// <summary>Gets the value of <b>providerKey</b> HTTP request parameter.</summary>
        /// <returns>Value stored in <b>providerKey</b> parameter or <b>null</b> if not found.</returns>
        public static string GetSearchViewCacheKey()
        {
            string providerKey = HttpContext.Current.Request["providerKey"];
            string cacheKey = !string.IsNullOrEmpty(providerKey) ? providerKey : null;
            return cacheKey;
        }

        #endregion

        #region GetDefaultTextSource.

        /// <summary>Gets message/text source as defined in <see cref="UserSession"/>.</summary>
        /// <returns>Object stored in <see cref="UserSession.MessageSource"/>.</returns>
        public static ITextSource GetMessageSource()
        {
            return UserSession.MessageSource;
        }

        #endregion
    }
}
